﻿using IServices;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Linq;
using YL.Core.Dto;
using YL.Core.Entity;
using YL.Core.Entity.Fluent.Validation;
using YL.NetCore.Attributes;
using YL.NetCore.NetCoreApp;
using YL.Utils.Extensions;
using YL.Utils.Pub;
using YL.Utils.Table;

namespace Method.SmartMeter.Controllers
{
    public class DeviceAlarmHistoryController : BaseController
    {
        private readonly IMeter_DeviceAlarmHistoryServices _DeviceAlarmHistoryServices;
        private readonly IMeter_DeviceAlarmDetailServices _DeviceAlarmDetailServices;

        public DeviceAlarmHistoryController(IMeter_DeviceAlarmHistoryServices DeviceAlarmHistoryServices, IMeter_DeviceAlarmDetailServices DeviceAlarmDetailServices)
        {
            _DeviceAlarmHistoryServices = DeviceAlarmHistoryServices;
            _DeviceAlarmDetailServices = DeviceAlarmDetailServices;
        }
        //DeviceAlarmHistory
        [HttpGet]
        [CheckMenu]
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult List([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            var sd = _DeviceAlarmHistoryServices.PageList(bootstrap, UserDtoCache.UserId);
            return Content(sd);
        }

        //DeviceAlarmDetails
        [HttpGet]
        [CheckMenu]
        public IActionResult DetailIndex()
        {
            if (!string.IsNullOrEmpty(Request.Query["HistoryId"]))
            {
                ViewBag.HistoryId = Convert.ToInt64(Request.Query["HistoryId"]);
            }
            return View();
        }

        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult DetailsList([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            Int64 HistoryId = Convert.ToInt64(Request.Query["HistoryId"]);
            var sd = _DeviceAlarmDetailServices.PageList(bootstrap, HistoryId, UserDtoCache.UserId);
            return Content(sd);
        }

    }
}